package models

import (
	"github.com/beego/beego/v2/client/orm"
)

/* 账号类型动态属性 */
type AccountField struct {
	FieldId      int `orm:"PK;auto"`
	FieldName    string
	FieldKey     string
	TypeId       int
	IsRequired   bool
	IsCiphertext bool
	MaxLen       int
	ValueType    uint16
	ValueRule    string
	FieldValue   interface{} `orm:"-"`
}

var FieldValueTypes = map[uint16]string{
	0: "文本", 1: "布尔", 2: "数字", 3: "可选值",
}

const table_field_name = "account_field"

func (t *AccountField) TableName() string {
	return table_field_name
}

//获取账号类型下的所有动态属性
func FindFieldsByTypeId(accountTypeId int) []*AccountField {
	var fields []*AccountField
	orm.NewOrm().QueryTable(table_field_name).Filter("type_id", accountTypeId).All(&fields)
	return fields
}

//根据id批量删除动态属性
func DelFieldByIds(fieldIds []int) (int64, error) {
	return orm.NewOrm().QueryTable(table_field_name).Filter("field_id__in", fieldIds).Delete()
}

//删除账号类型下的所有动态属性
func DelFieldByTypeId(typeId int) (int64, error) {
	return orm.NewOrm().QueryTable(table_field_name).Filter("type_id", typeId).Delete()
}
